const { AdminsLogin, SuperAdminsLogin3, AddAdmins, getAdmins,setAdmins,getData,getData2,getData3 } = require('../dao/adminsDao');

//普通管理员登录
module.exports.AdminsLogin = async function (username) {
  const data = await AdminsLogin(username)
  return data
}
//超级管理员登录
module.exports.SuperAdminsLogin2 = async function (msg) {
  const data = await SuperAdminsLogin3(msg)
  if (data) {
    return { message: '登录成功', status: 1, data }
  } else {
    return { message: '登录失败', status: 0, }
  }
}
//新增管理员
module.exports.AddAdmins = async (msg) => {
  const data = await AddAdmins(msg)
  if (data) {
    return { message: '新增成功', status: 1, data }
  } else {
    return { message: '新增失败', status: 0, }
  }
}
//获取管理员数据
module.exports.getAdmins = async (msg) => {
  const { select, input, currentPage, pageSize} = msg;
  let cha
  switch (select) {
    case '':
      cha = { power: 2 }
      break;
    case 'username':
      if (input) {
        cha = { username: { $regex: input, $options: '$i' }, power: 2 }
      } else { cha = { power: 2 } }
      break;
    case 'id':
      if (input) {
        cha = { _id: input, power: 2 }
      } else { cha = { power: 2 } }
      break;
    default: cha = { power: 2 };
  }
  const data = await getAdmins(cha,currentPage, pageSize)
  if (data) {
    return { message: '获取成功', status: 1, data }
  } else {
    return { message: '获取失败', status: 0, }
  }
}
//修改管理员信息
module.exports.setAdmins=async(msg)=>{
  const data = await setAdmins(msg)
  if (data) {
    return { message: '修改成功', status: 1, data }
  } else {
    return { message: '修改失败', status: 0, }
  }
}

module.exports.getData= async function(){
    const data = await getData()
    return data
}

module.exports.getData2= async function(){
    const data = await getData2()
    return data
}
module.exports.getData3= async function(){
    const data = await getData3()
    return data
}